package sample.util;

import java.io.*;
import java.util.ArrayList;

/**
 * Created by 耿秋鹏 on 2017/2/12.
 */
public class Company {
    //TODO 检查名单重复

    public ArrayList<String> getDefaultUser() {
        File directory = new File("");//设定为当前文件夹
        System.out.println(directory.getAbsolutePath());//获取绝对路径
        File file = new File(directory.getAbsoluteFile().toString() + "\\file.txt");
        return getUsersByFileName(file);
    }

    public ArrayList<String> getSpecialUser(){
        File directory = new File("");//设定为当前文件夹
        System.out.println(directory.getAbsolutePath());//获取绝对路径
        File file = new File(directory.getAbsoluteFile().toString() + "\\cache.txt");
        return getUsersByFileName(file);
    }

    private ArrayList<String> getUsersByFileName(File file) {
        ArrayList<String> arrayList = new ArrayList<>();
        try {
            FileReader reader = new FileReader(file);
            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(file), "utf-8");
            BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                arrayList.add(line);
                System.out.println(line);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return arrayList;
    }
}
